﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using University.Workshop.Presenters.Users;
using University.Workshop.Business;
using System.Collections.ObjectModel;

namespace University.Workshop.Presenters.Users
{
    public class PresenterSearchUser
    {
        ISearchUserView view;
        public PresenterSearchUser(ISearchUserView view)
        {
            this.view = view;
        }

        public void SearchUser()
        {
            try
            {
                Model.User u = new Model.User() { Person = new Model.Person() { Names = view.PersonNamesRelative, LastNames = view.PersonLastNamesRelative }, Login = view.Login };
                view.UserFinded = ManagerUser.SearchUserByParameter(u, view.StateUser);
            }
            catch (Exception ex)
            {
                view.UserFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }



        public void ShowDisableUser()
        {
            view.OpenDisableUserPopUp(ManagerUser.GetUserByUserId(view.UserSelected));
            UserForDisable = view.UserSelected;

            //if (UserForDisable.IsActive)



            /*if (view.NotifyConfirmationMessage("¿Está seguro que desea inhabilitar al usuario?"))
            {
                view.OpenDisableUserPopUp(ManagerUser.GetUserByUserId(view.UserSelected));
                UserForDisable = view.UserSelected;
            }*/
        }

        public void ShowEnableUser()
        {
            if (view.NotifyConfirmationMessage("¿Está seguro que desea habilitar al usuario?"))
            {
                view.OpenDisableUserPopUp(ManagerUser.GetUserByUserId(view.UserSelected));
                UserForDisable = view.UserSelected;
            }
        }

        public void EnableUser()
        {
            if (view.NotifyConfirmationMessage("Confirmacón de habilitación de usuario"))
            {
                ManagerUser.EnableUser(UserForDisable);
                view.NotifySystemMessage("El usuario fue habilitado exitosamente");
                UserForDisable = null;
                HideDisableUser();
                CleanSearch();
                //view.OpenDisableUserPopUp(ManagerUser.GetUserByUserId(view.UserSelected));
                //UserForDisable = view.UserSelected;
            }
            //view.GoToModifyUser(ManagerUser.GetUserByUserId(view.UserSelected));
        }

        public void DisableUser()
        {
            if (view.NotifyConfirmationMessage("Confirmacón de inhabilitación de usuario"))
            {
                ManagerUser.DisableUser(UserForDisable);
                view.NotifySystemMessage("El usuario fue deshabilitado exitosamente");
                UserForDisable = null;
                HideDisableUser();
                CleanSearch();
            }
        }

        public void HideDisableUser()
        {
            view.HideDisableUser();
        }

        private void CleanSearch()
        {
            view.Login = string.Empty;
            view.UserFinded = new Collection<Model.User>();
            view.PersonLastNamesRelative = string.Empty;
            view.PersonNamesRelative = string.Empty;
        }

        public Model.User UserForDisable { get; set; }

        public void ModifyUser()
        {
            view.GoToModifyUser(ManagerUser.GetUserByUserId(view.UserSelected));
        }




    }
}
